from tkinter import *
import tkinter as tk
import tkinter.messagebox #消息框
import AddStudent as AS
import Delete as DE
import Update as UP
import Find as F
import database as q
import Sexfind as SF
import sorsub as sb


class Mian:
    def __init__(self):
        root = Tk()
        root.title('学生成绩管理系统   作者:林丽璇    时间：2021.7.16')
        # logo = PhotoImage(file = "E:/study/图片1.png")
        # Label(root,image=logo,height=100,bg='LightBlue').grid(row=0,column=1)

        def add():
            AS.AddStudent()
        def edit():
            UP.Update()
        def dele():
            DE.Delete()
        def find():
            F.Find()

        def sfind():
            SF.Sexfind()

        def ss():
            sb.Sorsub()

        # def queryall():
        #     text.delete('1.0','end') #从第一行开始，全部删除
        #     number=0
        #     list=['学号:','姓名:','年龄:','性别:','班级:','电话:','地址:']
        #     result=q.QueryAll3()
        #     # print(result)
        #     for items in result:
        #         for index,item in enumerate(items):
        #             message=list[index]+str(item)+' '
        #             text.insert(INSERT,message)
        #             number+=1
        #             if number==7:
        #                 text.insert(INSERT,'\n')
        #                 number=0
        #     tk.messagebox.showinfo('提示', '显示成功!')
        #
        # def queryall2():
        #     text.delete('1.0','end') #从第一行开始，全部删除
        #     number=0
        #     list=['序号:','班级:','人数:']
        #     result=q.QueryAll3()
        #     # print(result)
        #     for items in result:
        #         for index,item in enumerate(items):
        #             message=list[index]+str(item)+' '
        #             text.insert(INSERT,message)
        #             number+=1
        #             if number==3:
        #                 text.insert(INSERT,'\n')
        #                 number=0
        #     tk.messagebox.showinfo('提示', '显示成功!')

        def queryall3():
            text.delete('1.0','end') #从第一行开始，全部删除
            number=0
            list = ['学号:', '姓名:', 'C语言:', 'java:', 'python:','总分:', '加权平均分:']
            result=q.QueryAll3()
            # print(result)
            for items in result:
                for index,item in enumerate(items):
                    message=list[index]+str(item)+' '
                    text.insert(INSERT,message)
                    number+=1
                    if number==7:
                        text.insert(INSERT,'\n')
                        number=0
            tk.messagebox.showinfo('提示', '显示成功!')

        Button(root, text='ID/姓名\n查询', width=10, height=2,bg='LightBlue',command=find).grid(row=2,column=2,sticky=W)
        Button(root, text='录入学生', width=10,height=2,bg='LightBlue',command=add).grid(row=1,column=2,sticky=W)
        Button(root, text='修改信息', width=10,height=2,bg='LightBlue',command=edit).grid(row=1,column=3,sticky=W)
        Button(root, text='按科目\n排序', width=10, height=2,bg='LightBlue',command=ss).grid(row=2, column=3, sticky=W)
        Button(root, text='删除学生', width=10,height=2,bg='LightBlue',command=dele).grid(row=1,column=4,sticky=N)
        Button(root, text='筛选', width=10, height=2,bg='LightBlue',command=sfind).grid(row=2, column=4, sticky=W)
        # Button(root, text='显示全部\n基本信息', width=10,height=2,bg='LightBlue',command=queryall).grid(row=2, column=2,sticky=W)
        # Button(root, text='显示全部\n班级信息', width=10,height=2,bg='LightBlue',command=queryall2).grid(row=2, column=3,sticky=W)
        Button(root, text='显示全部\n学生成绩', width=10, height=2,bg='LightBlue',command=queryall3).grid(row=1, column=1, sticky=W)

        text=tk.Text()
        text.grid(row=3, column=0)
        mainloop()
if __name__=='__main__':
    Mian()